<?php
declare (strict_types = 1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Db;
use think\facade\Env;

class ClearDb extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('cleardb')
            ->setDescription('清空数据库【危】');        
    }

    protected function execute(Input $input, Output $output){
        $dbName = Env::get('DATABASE.DATABASE', false);
        if (! $dbName) return ;
        $tables = Db::query('show table status from '. Env::get('DATABASE.DATABASE'));
        foreach ($tables as $one) {
            $sql = "DROP TABLE IF EXISTS {$one['Name']};";
            Db::execute($sql);
            $output->writeln($sql);
        }
    }
}
